package com.baiyue.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baiyue.entity.TableCategory;
import com.baiyue.mapper.TableCategoryMapper;
import com.baiyue.model.tableCategory.TableCategoryDataRequest;
import com.baiyue.model.tableCategory.TableCategoryDataResponse;
import com.baiyue.service.TableCategoryService;
import com.baiyue.utils.BeanMapperUtil;
import com.baomidou.mybatisplus.plugins.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @author 伍波
 * @date 2024-09-04
 */
@Service
public class TableCategoryServiceImpl implements TableCategoryService {
    private static final Logger logger = LoggerFactory.getLogger(TableCategoryServiceImpl.class);

    @Autowired
    private TableCategoryMapper tableCategoryMapper;

    /**
     * 根据分页请求查询商品分类列表
     *
     * @param request 分页查询请求对象，包含页码、每页大小和查询条件
     * @return 返回分页的商品分类数据响应对象
     */
    @Override
    public Page<TableCategoryDataResponse> findByPage(TableCategoryDataRequest request) {
        logger.info("查询商品分类列表入参:{}", JSONObject.toJSONString(request));
        Page<TableCategoryDataResponse> responsePage = new Page<>(request.getPage(),request.getSize());

        TableCategory tableCategory = BeanMapperUtil.map(request, TableCategory.class);
        List<TableCategory> resList = tableCategoryMapper.findByPage(tableCategory,responsePage);
        List<TableCategoryDataResponse> resDataList = BeanMapperUtil.mapList(resList, TableCategoryDataResponse.class);
        return responsePage.setRecords(resDataList);
    }
}
